package adv7;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket;

public class LoginThread extends Thread {
	private Socket s;

	public LoginThread(Socket s) {
		this.s = s;
	}

	@Override
	public void run() {
		try {
			InputStream in = s.getInputStream();
			OutputStream out = s.getOutputStream();
			BufferedReader br = new BufferedReader(new InputStreamReader(in));
			PrintWriter pw = new PrintWriter(out, true);// 第二个参数，自动刷新
			String name = br.readLine();
			String pass = br.readLine();
			System.out.println(s + "准备登录了");
			if (name.contains("liu") && pass.contains("bee")) {
				pw.println("登录成功，欢迎 " + name);
			} else {
				pw.println("错误的用户名或者密码");
			}
		} catch (IOException e) {
			// TODO 自动生成的 catch 块
			e.printStackTrace();
		} finally {
			try {
				s.close();
			} catch (Exception e) {
				// TODO 自动生成的 catch 块
				// e.printStackTrace();
			}
		}

	}
}
